<?php

class Templater {

	protected $engine_type = "";
	protected $templ_engine;

	function __construct($engine_type = "tortilla", $theme = "default_style", $base_dir = "") {

		$this->engine_type = $engine_type;

		if (empty($base_dir)) {
			$base_dir = TEMPLATES_DIR;
		}
		$base_dir .= DIRECTORY_SEPARATOR.$theme;

		switch ($this->engine_type) {
			case "smarty":
				$this->templ_engine = new Smarty();
				break;
			case "tortilla":
				$this->templ_engine = new Tortilla($base_dir);
				break;
		}
	}

	//==========================================================================================

	public function Assign($key, $value) {
		$this->templ_engine->Assign($key, $value);
	}

	//==========================================================================================

	public function Display($path) {
		$this->templ_engine->Display($path);
	}

	//==========================================================================================

	public function Fetch($path) {
		return $this->templ_engine->Fetch($path);
	}

	//==========================================================================================

	public function truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) {
		if ($this->engine_type == "tortilla") {
			return $this->templ_engine->truncate($string, $length, $etc, $break_words, $middle);
		}

		return false;
	}

	//==========================================================================================

	public function escape($string, $esc_type = 'html', $char_set = 'ISO-8859-1') {
		if ($this->engine_type == "tortilla") {
			return $this->templ_engine->escape($string, $esc_type, $char_set);
		}

		return false;
	}
}

?>